home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
os2
/
srefv12i.zip
/
srefquik.80
< prev
next >
Wrap
Text File
|
1997-03-27
|
12KB
|
363 lines
/* sre-filter ver 1.2i
Note that in many cases, this will call the SREF_MAINROUTINE(...)
But, by having a small filter grab many of the requests, we
can save substantial amounts of time.
----------------------------------------
SREFQUIK specific user-changable parameters:
NO_RECORDS.1, ..., NO_RECORDS.n and NO_RECORDS.0
A stem variable containing selectors that should NOT be subject
to post-filtering.
Use of NO_RECORDS complements NORECORD public_urls (it's
quicker to check then the PUBLIC_URLS themself).
Furthermore, cached hits (or literal public_Urls) will NOT
check the ACCESS_FILE for the NO_POSTFILTER permission. You can
use the NO_RECORDS. variables as a substitute.
NOTE:
* Too speed up processing, abbreviation matching is done. That is,
wildcards are NOT recognized.
For example: A NO_RECORDS value of DIR1/FOO will match both the
DIR1/FOO.HTM and DIR1/FOO2/BAR.HTM selectors.
* In other words: do NOT include * in the NO_RECORDS. stem variables
* You MUST include a NO_RECORDS.0=n variable, where n is the
number of NO_RECORDS variables you've specified.
NO_RECORDS_ONLY
To further speed up processing, you can suppress looking for
NORECORD PUBLIC_URLS. If NO_RECORDS_ONLY=1, then just the
NO_RECORDS. variables are checked. Of course, this does mean
being sure you have the appropriate NO_RECORDS. entries.
*/
no_records.0=0 /* no_records.0 MUST be specified */
no_records.1='/img'
no_records_only=0 /* 1=only look in no_records, 0=also look in public_urls */
/******************** End of user changable parameters *******/
parse arg source, request , seloriginal
if request=" " then return 'NODATA'
source0=source ; request0=request ;seloriginal0=seloriginal ;
parse var source myaddr port transaction who whoport .
os2e='os2environment'
response_status=' '
no_rec=-1
/*-check on libraries first */
foo=rxfuncquery('sysloadfuncs')
if foo=0 then
foo=rxfuncquery('rexxlibregister')
if foo<>0 then
signal dogoaway
/* ---------Get stuff sent from GOSERVE program -----------------*/
parse var request foo sel .
sel=strip(strip(sel,'l','/') ) /* get rid of leading / */
parse var request verb uri protocol . /* split up the request line */
enmadd="SREF_"||port||"_"
basesem='\SEM32\'||enmadd
ddir=0
/* ---- Do we need to initialize sre-filter ? --- */
sem_status=eventsem_query(basesem)
if sem_status<0 then
signal dogoaway
issent=completed()
if issent=0 then do
loadthreshold=value(enmadd||'loadthreshold',,'os2environment')
backupserverlist=value(enmadd||'backupserverlist',,'os2environment')
save_state=value(enmadd||'save_state',,'os2environment')
if loadthreshold>0 & BackupServerList \= '' then do
'EXTRACT CLIENTS'
if Clients > LoadThreshold then do
i1=transaction//(words(backupserverlist)+1)
if i1=0 then i1=1
auri=word(backupserverlist,i1)
auri2='http://'||auri||'/'||sel
'HEADER ADD Location:' auri2
'RESPONSE HTTP/1.0 302 Moved Temporarily' /* Set HTTP response line */
'STRING Redirect to backup server at ' auri
exit /* no postfiltering */
end
end
end /* end of load balancing check */
/* save some request specific variables? */
if save_state=1 then do
foo=sref_save_state(source,request,seloriginal,enmadd,port)
end
/* if call a prefilter, go to main routine */
pre_filter=value(enmadd||'PRE_FILTER',,'os2environment')
if pre_filter="FIRST" then
signal dogoaway
nhosts=value(enmadd||'HOSTS.0',,'os2environment')
if nhosts>0 then do
signal dogoaway
end
/* 2) MAKE SURE THE REQUEST IS STILL ACTIVE!!
(IF CACHING OCCURED, IT MIGHT NOT BE !! */
if issent<>0 then do
if check_norec(seloriginal)=1 then return ' '
post_filter_message="SREFQUIK: Cached file sent:"||seloriginal
if no_records_only=1 then signal do_post_filter
/* is it a public url with NORECORD option */
oof=upper(seloriginal)
call diinky oof
if pos('NORECORD',Useliteral)>0 then return ' '
signal do_post_filter
END
/* 3) Check for basic grooviness */
if left(protocol,4)\='HTTP' & protocol\='' then
signal dogoaway
/* 4) Is it one of the literal public_urlS ??. */
tsel=translate(sel)
call diinky tsel /* use globals */
if gotit>0 then do /* if gotit, then reset the sel */
/* if it's a literal public file, return it now! */
if abbrev(useliteral,"LITERAL")=1 then do
if exact_name<>" " then do
afile=exact_name
end
else do
parse var usesel asel '?' .
ddir=datadir()
afile=translate(ddir||asel,'\','/')
if pos('~',afile)>0 then do
home_dir=value(enmadd||'HOME_DIR',,os2e)
afile=sref_replacestrg(afile,'~',home_dir) ;
end
end
ii=stream(afile,'c','query exists')
if ii="" then do
transaction="NOFILE_"||transaction
/* reset to original on error */
source=source0 ; seloriginal=seloriginal0 ; request=request0 ;
signal dogoaway
end
else do
atype=sref_mediatype(afile)
'FILE TYPE ' atype ' NAME ' afile
post_filter_message="Literal public_URL returned:" ||afile
response_status='200 '||dosdir(afile,'s')
signal do_post_filter
end
end /* useliteral */
/* non literal public url */
transaction="PUBFILE_"||transaction
source=myaddr' 'port' 'transaction' 'who' 'whoport
seloriginal='_'||USELITERAL||','||usesel' 'seloriginal
end /* gotit */
/* if here, not a literal... */
dogoaway: /* call the main filter (with perhaps flags to indicate issues */
/* check on advanced REXX functions */
foo=rxfuncquery('sysloadfuncs')
if foo=1 then do
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
end
foo=rxfuncquery('rexxlibregister')
if foo=1 then do
call rxfuncadd 'rexxlibregister','rexxlib', 'rexxlibregister'
call rexxlibregister
end
aroutine='SREF_MAIN_'||port
foo=load_bigone(aroutine,port)
signal on error name yike2 ; signal on syntax name yike2 ;
wow2=' '
goaway='wow='||aroutine||'(source,request,seloriginal)'
interpret goaway
wow2=wow
yike2: ;
return wow2
/* jump here after completion code -- do record option and/or post-filter */
do_post_filter:
/* check the no_records?*/
if no_rec=-1 then do
if check_norec(seloriginal)=1 then return ' '
end
IF RESPONSE_STATUS=' ' THEN RESPONSE_STATUS='200 '||EXTRACT('BYTESSENT')
/*check for 400 status */
are1=strip(word(response_status,1))
if are1>399 then
record_option='NO'
else
record_option=strip(value(enmadd||'RECORD_OPTION',,os2e))
post_filter=strip(value(enmadd||'POST_FILTER',,os2e))
write_logs=strip(value(enmadd||'write_logs',,os2e))
if useliteral="LITERAL_NORECORD" then do
if save_state=1 then foo=sysfiledelete(tcachfile)
return ' '
end
if record_option="NO" & post_filter=0 & write_logs=0 then do /* nothing to do in post filter */
if save_state=1 then foo=sysfiledelete(tcachfile)
return ' '
end
a=rxqueue('s',enmadd||'POSTF')
record_all_file=value(enmadd||'RECORD_ALL_FILE',,os2e)
postfilter_name=value(enmadd||'POSTFILTER_NAME',,os2e)
if ddir=0 then ddir=datadir()
tempfile=ddir'$'transaction'.'port /* Often used */
servername=servername()
browser=' ';authuser=' '; clientname0=who
thereferer=reqfield('referer')
if write_logs=1 then do
clientname0=clientname()
browser=reqfield('user-agent')
goo=reqfield('AUTHORIZATION:')
authuser='-'
if goo<>" " then do
parse var goo . m64 . /* get the encoded cookie */
dec=pack64(m64) /* and decode it */
parse upper var dec authuser ':' . /* split to userid */
end
end
fuse=' '
if save_state=1 then do
tdir=strip(TEMPDATA_DIR,'t','\')||'\'
fuse=dostempname(tdir||'_T??????.TMP')
foo2=dosrename(tcachfile,fuse)
if foo2=0 then fuse=' '
end
selrec=sref_replacestrg(seloriginal,',','%2c','ALL')
request0=sref_replacestrg(request,',','%2c','ALL')
post_filter_message=sref_replacestrg(post_filter_message,',','%2c','ALL')
push record_option ',' record_all_file ',' post_filter ',' postfilter_name ',' port ',' ,
post_filter_message ',' source ',' request0 ',' selrec ',' ,
tempfile ',' servername ',' ',' afile ',' who ',' ,
enmadd ',' thereferer ',' fuse ',' RESPONSE_STATUS ',' write_logs ',' clientname0 ',' authuser ',' browser
aa=eventsem_post(basesem||'POSTF')
return ' ' /* note that postfilter and recorder don't need to tell the filter anything*/
/* ------------------------------------------------- */
/* Routine to load srefbig, if neessary */
/* ------------------------------------------------- */
load_bigone:procedure expose transaction
parse arg aroutine,aport
if transaction=1 then
foo=macrodrop(aroutine) /* makesure you refresh on first transaction */
foo=macroquery(aroutine)
if foo="" | foo=0 then do
say " SREFQUIK: Loading main SRE-Filter code into macrospace "foo
aff='SREFILTR.'||aport
foo2=macroadd(aroutine,aff)
if foo2=0 then do
say " error loading sre-filter main program into macrospace "foo2
'string Server is busy, try again later '
exit ' '
end
end
return 0
/*********/
/* check the no_records. list. Return 1 if "norecord" pertains */
check_norec:procedure expose no_records. no_rec enmadd os2e
parse upper arg s1
no_rec=strip(value(enmadd||'NO_NO_RECORD',,os2e))
select /* deal with !directives */
when abbrev(s1,'!NORECORD') & no_rec<>1 then return 1 /* enuf said */
when abbrev(upper(s1),'!SENDAS_')=1 then do /* strip !sendas_ */
ooy=pos('/',s1)
ooy2=pos('?',s1)
if ooy2>0 & ooy2< ooy then ooy=ooy2
s1=substr(s1,ooy+1)
end
when abbrev(upper(s1),'!FORCE')=1 then s1=substr(s1,8)
otherwise nop
end
do mm=1 to no_records.0
al=strip(translate(no_records.mm,'/','\'))
al=upper(strip(al,'l','/'))
if abbrev(s1,al)=1 then return 1
end
return 0
/********************************/
diinky:
parse arg tsel
gotit=0 ; doexact=0 ; asterat=0 ; afteraster=0
public_urls.0=value( enmadd||'public_urlS.0',,'os2environment') ;
do m=1 to public_urls.0
public_urls.m=value( enmadd||'public_urlS.'||m,,'os2environment' );
parse var public_urls.m purl isliteral aname0
purl=strip(purl)
ares=sref_wildcard(tsel,purl||' '||aname0,doexact)
parse var ares astat "," afname ; astat=strip(astat)
if astat=0 then iterate /* no match */
if astat=1 then do
usesel=sel ;
useliteral=strip(upper(isliteral)) ;
exact_name=' '
if aname0<>' ' then exact_name=strip(afname)
gotit=m
leave /*first exact match rules */
end
/* astat=2;; non exact: see if it's a "better match" (more chars before *) */
foo1=pos('*',purl)
if foo1 >= asterat then do
tmp1=length(purl)-foo1
if foo1>asterat | tmp1>afteraster then do
asterat=foo1 ; afteraster=tmp1
usesel=sel ;
useliteral=strip(upper(isliteral)) ;
exact_name=' '
if aname0<>' ' then exact_name=strip(afname)
gotit=m
end /* either condition */
end /* ge asterat */
end
return 0